package com.sxj.corejava.code08_常用类.日期类;

import java.util.Calendar;
import java.util.Date;

/**
 * @author 石小俊
 * @date 2025年02月17日
 */
public class Test05_日历类 {

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        // 获取此日历对象所表示的日期
        Date date = calendar.getTime();
        System.out.println(DateUtil.toString(date));

        // 设置指定日期所表示的日历
        calendar.setTime(DateUtil.getNextDay(date));

        long time = calendar.getTimeInMillis();
        System.out.println(time);
        Date date2 = new Date(time);
        System.out.println(DateUtil.toString(date2));

        date = calendar.getTime();
        System.out.println(DateUtil.toString(date));
        System.out.println("年份:" + calendar.get(Calendar.YEAR));
        // 月份取值为:0-11,真正的月份值应该+1
        System.out.println("月份:" + (calendar.get(Calendar.MONTH) + 1));
        System.out.println("天数:" + calendar.get(Calendar.DATE));
        System.out.println("天数:" + calendar.get(Calendar.DAY_OF_MONTH));
        // 十二小时制
        System.out.println("十二小时制小时数:" + calendar.get(Calendar.HOUR));
        // 二十四小时制
        System.out.println("二十四小时制小时数:" + calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println("分钟数:" + calendar.get(Calendar.MINUTE));
        System.out.println("秒数:" + calendar.get(Calendar.SECOND));
        System.out.println("毫秒数:" + calendar.get(Calendar.MILLISECOND));
        System.out.println("年中的周数:" + calendar.get(Calendar.WEEK_OF_YEAR));
        System.out.println("年中的天数:" + calendar.get(Calendar.DAY_OF_YEAR));

        System.out.println("设置前:" + DateUtil.toString(calendar.getTime()));
        calendar.set(Calendar.YEAR, 2024);
        calendar.set(Calendar.MONTH, 4);
        // 支持运算,当月份超出范围之后,年份进一,月份-11
        calendar.set(Calendar.MONTH, 13);
        calendar.set(Calendar.DATE, 30);

        calendar.set(Calendar.YEAR, 2024);
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.DATE, 30);


        calendar.set(Calendar.MONTH, 2);
        calendar.set(Calendar.DATE, 0);
        System.out.println("设置后:" + DateUtil.toString(calendar.getTime()));

        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.YEAR, -1);
        calendar.add(Calendar.DATE, 1);
        System.out.println(DateUtil.toString(calendar.getTime()));

        calendar.clear();
        System.out.println("清空日期后:" + DateUtil.toString(calendar.getTime()));

        calendar = Calendar.getInstance();
        System.out.println("年份可能的最大值:" + calendar.getActualMaximum(Calendar.YEAR));
        System.out.println("月份可能的最大值:" + calendar.getActualMaximum(Calendar.MONTH));
        System.out.println("天数可能的最大值:" + calendar.getActualMaximum(Calendar.DATE));
        calendar.add(Calendar.MONTH, 1);
        System.out.println("天数可能的最大值:" + calendar.getActualMaximum(Calendar.DATE));

        // 测试工具类
        int day = DateUtil.getDay(2024, 2);
        System.out.println("2024年2月份最多:" + day + "天");
        day = DateUtil.getDay(2025, 2);
        System.out.println("2025年2月份最多:" + day + "天");
        day = DateUtil.getDay(2025, 3);
        System.out.println("2025年3月份最多:" + day + "天");
        day = DateUtil.getDay(2025, 4);
        System.out.println("2025年4月份最多:" + day + "天");
        System.out.println("******************************");
        day = DateUtil.getDay2(2024, 2);
        System.out.println("2024年2月份最多:" + day + "天");
        day = DateUtil.getDay2(2025, 2);
        System.out.println("2025年2月份最多:" + day + "天");
        day = DateUtil.getDay2(2025, 3);
        System.out.println("2025年3月份最多:" + day + "天");
        day = DateUtil.getDay2(2025, 4);
        System.out.println("2025年4月份最多:" + day + "天");
    }


}
